//
//  ChannelViewController.m
//  HappyStore
//
//  Created by pzx on 16/5/6.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "ChannelViewController.h"
#import "goveDetailVC.h"
#import "goveSearchVC.h"
#import "pinDaoHeadCell.h"
#import "pinDaoModel.h"

@interface ChannelViewController ()<UITableViewDataSource,UITableViewDelegate,NSXMLParserDelegate,UISearchBarDelegate,selectedAddressDelegate>{
     NSString *fileName;
    NSString * tuijianName;
    
     NSMutableArray *aArr;          NSMutableArray *bArr;           NSMutableArray *cArr;           NSMutableArray *dArr;
     NSMutableDictionary * aDict;   NSMutableDictionary * bDict;    NSMutableDictionary * cDict;    NSMutableDictionary * dDict;
    
     NSMutableArray *eArr;          NSMutableArray *fArr;           NSMutableArray *gArr;           NSMutableArray *hArr;
     NSMutableDictionary * eDict;   NSMutableDictionary * fDict;    NSMutableDictionary * gDict;    NSMutableDictionary * hDict;
    
     NSMutableArray *jArr;          NSMutableArray *kArr;           NSMutableArray *lArr;           NSMutableArray *mArr;
     NSMutableDictionary * jDict;   NSMutableDictionary * kDict;    NSMutableDictionary * lDict;    NSMutableDictionary * mDict;
    
     NSMutableArray *nArr;          NSMutableArray *pArr;           NSMutableArray *qArr;           NSMutableArray *rArr;
     NSMutableDictionary * nDict;   NSMutableDictionary * pDict;    NSMutableDictionary * qDict;    NSMutableDictionary * rDict;
    
     NSMutableArray *sArr;          NSMutableArray *tArr;           NSMutableArray *wArr;           NSMutableArray *xArr;
     NSMutableDictionary * sDict;   NSMutableDictionary * tDict;    NSMutableDictionary * wDict;    NSMutableDictionary * xDict;
    
     NSMutableArray *yArr;          NSMutableArray *zArr;
     NSMutableDictionary * yDict;   NSMutableDictionary * zDict;
}

@property (strong, nonatomic) NSMutableArray *addressArr;
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (strong,nonatomic) NSString *documentsPath;
@property (strong, nonatomic) NSMutableArray * titleArr;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (strong, nonatomic) NSArray * tuijianArr;
@property (strong, nonatomic) UIView * backView;

@end

@implementation ChannelViewController

#pragma mark - 初始化
//doc路径
-(NSString *)documentsPath
{
    if (!_documentsPath) {
        _documentsPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
    }
    return _documentsPath;
}

-(NSArray *)tuijianArr{
    if (!_tuijianArr) {
        _tuijianArr = [NSArray array];
    }
    return _tuijianArr;

}

-(NSMutableArray *)titleArr{

    if (!_titleArr) {
        _titleArr = [NSMutableArray array];
    }
    
    return _titleArr;

}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
        
        NSArray *list=self.navigationController.navigationBar.subviews;
        
        for (id obj in list) {
            
            if ([obj isKindOfClass:[UIImageView class]]) {
                
                UIImageView *imageView=(UIImageView *)obj;
                
                NSArray *list2=imageView.subviews;
                
                for (id obj2 in list2) {
                    
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        
                        UIImageView *imageView2=(UIImageView *)obj2;
                        
                        imageView2.hidden=YES;
                        
                    }
                    
                }
                
            }
            
        }
        
    }

    fileName=[self.documentsPath stringByAppendingPathComponent:@"addressFile.plist"];
    tuijianName = [self.documentsPath stringByAppendingPathComponent:@"tuijianNameFile.plist"];
    _addressArr=[[NSArray arrayWithContentsOfFile:fileName] copy];
    
    NSMutableDictionary * dict = [[NSDictionary dictionaryWithContentsOfFile:tuijianName] copy];
    
    if (_addressArr) {
        self.titleArr = nil;
        
        _tuijianArr = dict[@"tuijianArr"];
         [self.titleArr addObject:@"#"];

        for (NSDictionary * dict in self.addressArr) {
            [self.titleArr addObject:dict[@"title"]];
        }
        
        [self.tableview reloadData];
        
    }else{
    
    self.addressArr = nil;
    
        [self sendRequest];

    }
    
    NSString * timeStr;
    timeStr = [CustomExcetion prettyDateWithReference:[CustomExcetion dateFromString:dict[@"time"]]];
    
    if ([timeStr isEqualToString:@"5天前"]) {
        
        [self sendRequest];
        
    }
    
    //segu
    NSArray *segmentedArray = [NSArray arrayWithObjects:@"国内",@"国外",@"筛选",nil];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    segmentedControl.frame = CGRectMake(0.0, 0.0, 240, 35.0);
    UIFont *font = [UIFont systemFontOfSize:14];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont];
    [segmentedControl setTitleTextAttributes:dic forState:UIControlStateNormal];
    segmentedControl.selectedSegmentIndex = 0;
    segmentedControl.tintColor = [UIColor whiteColor];
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    [segmentedControl addTarget:self  action:@selector(indexDidChangeForSegmentedControl:)
               forControlEvents:UIControlEventValueChanged];
    [self.navigationItem setTitleView:segmentedControl];
    
    self.tabBarController.tabBar.hidden = NO;
    
    self.backView.hidden = YES;
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = YES;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.title = @"频道";
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"频道";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.tableHeaderView.backgroundColor =[UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1];
    self.tableview.sectionIndexColor = [UIColor grayColor];
    self.tableview.sectionIndexBackgroundColor = [UIColor clearColor];
    self.tableview.sectionIndexTrackingBackgroundColor=[UIColor clearColor];
    
    self.searchBar.delegate = self;
    
    // 声明这张图片用原图(别渲染)
    UIImage *selectedImgitemHome = [UIImage imageNamed:@"pingdao-blue"];
    selectedImgitemHome = [selectedImgitemHome imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.navigationController.tabBarItem setSelectedImage:selectedImgitemHome];

//    [self sendRequest];
    
    //监听通知
    [self setUpListenEvent];
    
    //占位图
    self.backView = [[UIView alloc]init];
    self.backView.frame = CGRectMake(0, self.tableview.y, screenW, screenH - self.searchBar.y - self.searchBar.height);
    self.backView.backgroundColor = [UIColor whiteColor];
    UIImageView * img = [[UIImageView alloc]init];
    img.width = screenW/2;
    img.height = 150;
    img.x = screenW/2 - img.width/2;
    img.y = 60;
    img.image = [UIImage imageNamed:@"加载失败"];
    [self.backView addSubview:img];
    [self.view addSubview:self.backView];
    self.backView.hidden = YES;
    NSDictionary *dicPinDao = [NSDictionary dictionaryWithObject:@"pinDaoSend" forKey:@"string"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pinDaoSendtoVC" object:nil userInfo:dicPinDao];

}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.addressArr.count + 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        
        return 1;
        
    }else{
    
    NSDictionary * dict = self.addressArr[section - 1];
    NSArray * arr = dict[@"cities"];
    return arr.count;
        
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * cellId = @"cityCell";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    pinDaoHeadCell *pindaocell = [pinDaoHeadCell cellWithTableView:tableView];
    pinDaoModel * model = [[pinDaoModel alloc]init];
    model.mtArr = [self.tuijianArr copy];
    
    if (indexPath.section == 0) {
        pindaocell.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1];
        pindaocell.model = model;

        return pindaocell;
        
    }else{
    NSDictionary * dict = self.addressArr[indexPath.section - 1];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        
    }

    NSArray * arr = dict[@"cities"];
    NSDictionary * dataDict = arr[indexPath.row];
    
    cell.textLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.text = dataDict[@"userName"];
    
    return cell;
        
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section != 0) {
        
        NSDictionary * dict = self.addressArr[indexPath.section - 1];
        NSArray * arr = dict[@"cities"];
        NSDictionary * dataDict = arr[indexPath.row];
        goveDetailVC * goveDetail = [[goveDetailVC alloc]init];
        goveDetail.userId = dataDict[@"userId"];
        goveDetail.userType = dataDict[@"userType"];
        self.tabBarController.tabBar.hidden = YES;
        [self.navigationController pushViewController:goveDetail animated:YES];
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (self.tuijianArr.count%3==0) {
            return self.tuijianArr.count/3*45 +10;
        }else{
            return (self.tuijianArr.count/3+1) * 45 +10;
        }
    }else{
        
        return 44;
        
    }
}

//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    
//    if (section == 0) {
//        
//        return @"推荐城市";
//    }else{
//        
//        NSDictionary * dict = self.addressArr[section - 1];
//        return dict[@"title"];
//        
//    }
//}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = RGB(247, 247, 247);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 4, screenW, 21)];
    
    titleLabel.textColor = RGB(117, 117, 117);
    titleLabel.font = [UIFont systemFontOfSize:16];
    if (section == 0) {
        
        titleLabel.text = @"推荐城市";
    }else{
        
        NSDictionary * dict = self.addressArr[section - 1];
        titleLabel.text = dict[@"title"];
        
    }
    [view addSubview:titleLabel];
    return view;
}
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    
    return self.titleArr;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    return 1;
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    return 1;
//}
#pragma mark - 监听通知
-(void)setUpListenEvent{
    
    //分类通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickCategoryChange:) name:@"clicktTuiJian" object:nil];

}

-(void)clickCategoryChange:(NSNotification *)notification{
    NSString * userId = notification.userInfo[@"userId"];
    NSString * userType = notification.userInfo[@"userType"];

    goveDetailVC * goveDetail = [[goveDetailVC alloc]init];
    goveDetail.userId = userId;
    goveDetail.userType = userType;
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:goveDetail animated:YES];
    
}

#pragma mark - segument
-(void)indexDidChangeForSegmentedControl:(id)sender{
    UISegmentedControl* control = (UISegmentedControl*)sender;
    SelectedAddress *selectAddress = [SelectedAddress sharedSelectedAddress];
    selectAddress.delegatee = self;
    [selectAddress btnClickAddress];
    switch (control.selectedSegmentIndex) {
        case 0:
            selectAddress.hidden = YES;
            self.backView.hidden = YES;
//            [self.tableview reloadData];
            break;
        case 1:
            self.backView.hidden = NO;
            selectAddress.hidden = YES;
//            NSLog(@"-----------我是国外");
            break;
        case 2:
            
            [selectAddress btnClickAddress];

            break;
            
        default:
            break;
    }
}
#pragma mark - 所在地代理
- (void)seceltedRowSshowMsg:(NSString *)showMsg andProvince:(NSString *)strProvince andCity:(NSString *)strCity andDistrict:(NSString *)strDistrict
{
    goveDetailVC * goveDetail = [[goveDetailVC alloc]init];
    NSString * address = [NSString stringWithFormat:@"%@,%@,%@",strProvince,strCity,strDistrict];
    goveDetail.addressStr = strDistrict;
    goveDetail.userType = @"3";
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:goveDetail animated:YES];
    
}

-(void)sendRequest{
    aArr = [NSMutableArray array];              bArr = [NSMutableArray array];              cArr = [NSMutableArray array];
    aDict = [NSMutableDictionary dictionary];   bDict = [NSMutableDictionary dictionary];   cDict = [NSMutableDictionary dictionary];
    
    dArr = [NSMutableArray array];              eArr = [NSMutableArray array];              fArr = [NSMutableArray array];
    dDict = [NSMutableDictionary dictionary];   eDict = [NSMutableDictionary dictionary];   fDict = [NSMutableDictionary dictionary];
    
    gArr = [NSMutableArray array];              hArr = [NSMutableArray array];              jArr = [NSMutableArray array];
    gDict = [NSMutableDictionary dictionary];   hDict = [NSMutableDictionary dictionary];   jDict = [NSMutableDictionary dictionary];
    
    kArr = [NSMutableArray array];              lArr = [NSMutableArray array];              mArr = [NSMutableArray array];
    kDict = [NSMutableDictionary dictionary];   lDict = [NSMutableDictionary dictionary];   mDict = [NSMutableDictionary dictionary];
    
    nArr = [NSMutableArray array];              pArr = [NSMutableArray array];              qArr = [NSMutableArray array];
    nDict = [NSMutableDictionary dictionary];   pDict = [NSMutableDictionary dictionary];   qDict = [NSMutableDictionary dictionary];
    
    rArr = [NSMutableArray array];              sArr = [NSMutableArray array];              tArr = [NSMutableArray array];
    rDict = [NSMutableDictionary dictionary];   sDict = [NSMutableDictionary dictionary];   tDict = [NSMutableDictionary dictionary];
    
    wArr = [NSMutableArray array];              xArr = [NSMutableArray array];              yArr = [NSMutableArray array];
    wDict = [NSMutableDictionary dictionary];   xDict = [NSMutableDictionary dictionary];   yDict = [NSMutableDictionary dictionary];
    
    zArr = [NSMutableArray array];
    zDict = [NSMutableDictionary dictionary];
    NSString *urlStr = @"getGove_app_myHome.im";
    
    [self showRoundProgressWithTitle:@"请稍后..."];
    

    [LSHttpTool sendHttpData:urlStr params:nil success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            _titleArr = [NSMutableArray array];
            _addressArr = [NSMutableArray array];
            _tuijianArr = dicInfo[@"data"][@"tuijianGove"];
            
            NSArray * dataArr = [NSArray array];
            dataArr = dicInfo[@"data"][@"gove"];
            
            for (int i = 0; i < dataArr.count; i++) {
                NSString * str = [self firstCharactor:dataArr[i][@"userName"]];
                [self strForAddress:str dict:dataArr[i]];
            }
            
            [_addressArr addObject:aDict];
            [_addressArr addObject:bDict];
            [_addressArr addObject:cDict];
            [_addressArr addObject:dDict];
            [_addressArr addObject:eDict];
            [_addressArr addObject:fDict];
            [_addressArr addObject:gDict];
            [_addressArr addObject:hDict];
            [_addressArr addObject:jDict];
            [_addressArr addObject:kDict];
            [_addressArr addObject:lDict];
            [_addressArr addObject:mDict];
            [_addressArr addObject:nDict];
            [_addressArr addObject:pDict];
            [_addressArr addObject:qDict];
            [_addressArr addObject:rDict];
            [_addressArr addObject:sDict];
            [_addressArr addObject:tDict];
            [_addressArr addObject:wDict];
            [_addressArr addObject:xDict];
            [_addressArr addObject:yDict];
            [_addressArr addObject:zDict];
            
            [_addressArr writeToFile:fileName atomically:YES];
            
            NSDate *currentDate = [NSDate date];//获取当前时间，日期
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
            NSString *dateString = [dateFormatter stringFromDate:currentDate];
            
            NSMutableDictionary * dict = [NSMutableDictionary dictionary];
            dict[@"time"] = dateString;
            dict[@"tuijianArr"] = _tuijianArr;
            [dict writeToFile:tuijianName atomically:YES];
            
            [self.titleArr addObject:@"#"];
            
            for (NSDictionary * dict in self.addressArr) {
                [self.titleArr addObject:dict[@"title"]];
            }
            
            [self hideBubble];
        }else{

            [self showErrorWithTitle:@"暂无数据" autoCloseTime:2];

        }
        
        [self.tableview reloadData];
        
    } failure:^(NSError *error) {

        [self showErrorWithTitle:@"获取失败" autoCloseTime:2];
        
    }];

}
#pragma mark - searchbar delegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{

        
    goveSearchVC * goveSearch = [[goveSearchVC alloc]init];
    [self.navigationController pushViewController:goveSearch animated:YES];


    return NO;
}


//获取拼音首字母(传入汉字字符串, 返回大写拼音首字母)
- (NSString *)firstCharactor:(NSString *)aString
{
    //转成了可变字符串
    NSMutableString *str = [NSMutableString stringWithString:aString];
    //先转换为带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
    //再转换为不带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
    //转化为大写拼音
    NSString *pinYin = [str capitalizedString];
    //获取并返回首字母
    return [pinYin substringToIndex:1];
}

-(void)strForAddress:(NSString *)aString dict:(NSDictionary *)dict{
    
    if ([aString isEqualToString:@"A"]) {
        
        [aArr addObject:dict];
        [aDict setValue:@"A" forKey:@"title"];
        [aDict setValue:aArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"B"]){
        
        [bArr addObject:dict];
        [bDict setValue:@"B" forKey:@"title"];
        [bDict setValue:bArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"C"]){
        
        [cArr addObject:dict];
        [cDict setValue:@"C" forKey:@"title"];
        [cDict setValue:cArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"D"]){
        
        [dArr addObject:dict];
        [dDict setValue:@"D" forKey:@"title"];
        [dDict setValue:dArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"E"]){
        
        [eArr addObject:dict];
        [eDict setValue:@"E" forKey:@"title"];
        [eDict setValue:eArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"F"]){
        
        [fArr addObject:dict];
        [fDict setValue:@"F" forKey:@"title"];
        [fDict setValue:fArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"G"]){
        
        [gArr addObject:dict];
        [gDict setValue:@"G" forKey:@"title"];
        [gDict setValue:gArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"H"]){
        
        [hArr addObject:dict];
        [hDict setValue:@"H" forKey:@"title"];
        [hDict setValue:hArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"J"]){
        
        [jArr addObject:dict];
        [jDict setValue:@"J" forKey:@"title"];
        [jDict setValue:jArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"K"]){
        
        [kArr addObject:dict];
        [kDict setValue:@"K" forKey:@"title"];
        [kDict setValue:kArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"L"]){
        
        [lArr addObject:dict];
        [lDict setValue:@"L" forKey:@"title"];
        [lDict setValue:lArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"M"]){
        
        [mArr addObject:dict];
        [mDict setValue:@"M" forKey:@"title"];
        [mDict setValue:mArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"N"]){
        
        [nArr addObject:dict];
        [nDict setValue:@"N" forKey:@"title"];
        [nDict setValue:nArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"P"]){
        
        [pArr addObject:dict];
        [pDict setValue:@"P" forKey:@"title"];
        [pDict setValue:pArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"Q"]){
        
        [qArr addObject:dict];
        [qDict setValue:@"Q" forKey:@"title"];
        [qDict setValue:qArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"R"]){
        
        [rArr addObject:dict];
        [rDict setValue:@"R" forKey:@"title"];
        [rDict setValue:rArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"S"]){
        
        [sArr addObject:dict];
        [sDict setValue:@"S" forKey:@"title"];
        [sDict setValue:sArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"T"]){
        
        [tArr addObject:dict];
        [tDict setValue:@"T" forKey:@"title"];
        [tDict setValue:tArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"W"]){
        
        [wArr addObject:dict];
        [wDict setValue:@"W" forKey:@"title"];
        [wDict setValue:wArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"X"]){
        
        [xArr addObject:dict];
        [xDict setValue:@"X" forKey:@"title"];
        [xDict setValue:xArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"Y"]){
        
        [yArr addObject:dict];
        [yDict setValue:@"Y" forKey:@"title"];
        [yDict setValue:yArr forKey:@"cities"];
        
    }else if([aString isEqualToString:@"Z"]){
        
        [zArr addObject:dict];
        [zDict setValue:@"Z" forKey:@"title"];
        [zDict setValue:zArr forKey:@"cities"];
        
    }


}
@end
